/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controller;

import com.model.Dokument;
import com.model.Dosen;
import com.model.Surat;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author priska
 */
public class PengendaliPeriksaSuratDokument {

    public static ArrayList<Dosen> dataDosen = new ArrayList<>();

    public static void tambahDosen(Dosen dosen) {
        dataDosen.add(dosen);
    }

    public static String bacaDataDosen() {
        if (dataDosen.isEmpty() == false) {
            String yuk = new String();
            for (int i = 0; i < dataDosen.size(); i++) {
                Dosen ment = dataDosen.get(i);
                yuk += "NIP : " + ment.getNIP() + "ALAMAT: " + ment.getAlamat() + "PENERIMA:" + ment.getNama();
            }
            return yuk;
        } else {
            return "Kosong";
        }
    }

    public static void tambahtableDosen(Dosen en) throws SQLException {
        Connection con = com.model.Connection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "hr");
        Statement stat = con.createStatement();
        String sql = "insert into DOSEN(NIP, ALAMAT,PENERIMA('"
                + en.getNIP() + "','" + en.getAlamat() + "','" + en.getNama() + "')";

        stat.executeUpdate(sql);
        con.close();
    }

    public static void simpanTabelDosen() throws SQLException {
        if (dataDosen.isEmpty() == false) {
            Connection con = com.model.Connection.open("jdbc:oracle:thin:@localhost:1521:XE", "hr", "hr");
            Statement stat = con.createStatement();
            int i = 0;
            while (i < dataDosen.size()) {
                String sql = "insert into DOSEN(NIP, ALAMAT,PENERIMA('"
                        + dataDosen.get(i).getNIP() + "','" + dataDosen.get(i).getAlamat() + "','" + dataDosen.get(i).getNama() + "')";
                stat.executeUpdate(sql);
                i++;
            }
            con.close();
        }
    }
}
